From: Robert Lipe Date: Sun, 14 Apr 2019 00:26:04 +0000 (-0500) Subject: Fix GUI upgrade check to handle upgrade from x-betaFOO to x. X-Git-Tag: archive/raspbian/1.10.0+ds-2+rpi1~1^2~12^2~8^2~9 X-Git-Url: https://dgit.raspbian.org/%22http://www.example.com/cgi/%22/%22http:/www.example.com/cgi/%22?a=commitdiff_plain;h=028ef4713c8014ff69dfa023994bd4a2e3717219;p=gpsbabel.git Fix GUI upgrade check to handle upgrade from x-betaFOO to x. --- diff --git a/configure b/configure index 4c865ec37..95e230beb 100755 --- a/configure +++ b/configure @@ -2209,7 +2209,7 @@ DOCVERSION=1.6.0 # Increase GBBUILD for a new release (why? Where is this ever used?) # A: it's used by win32/gpsbabel.rc.in which is used by the setup program, GBBUILD=29 -PACKAGE_RELEASE="-beta20200413" +PACKAGE_RELEASE="-beta20190413" cat >>confdefs.h <<_ACEOF #define PACKAGE_RELEASE "$PACKAGE_RELEASE" diff --git a/gbversion.h b/gbversion.h index df6233abd..0754c8e65 100644 --- a/gbversion.h +++ b/gbversion.h @@ -4,5 +4,5 @@ * * Isn't simplification via automation grand? */ -#define VERSION "1.6.0-beta20200413" +#define VERSION "1.6.0-beta20190413" #define WEB_DOC_DIR "http://www.gpsbabel.org/htmldoc-1.6.0" diff --git a/gui/upgrade.cc b/gui/upgrade.cc index 8ce6b777d..77c0ba187 100644 --- a/gui/upgrade.cc +++ b/gui/upgrade.cc @@ -27,20 +27,21 @@ #include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - - -#if 0 +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + + +#if 1 static const bool testing = true; #else static const bool testing = false; @@ -169,6 +170,38 @@ UpgradeCheck::updateStatus UpgradeCheck::getStatus() return updateStatus_; } +// GPSBabel version numbers throughout the code mostly predate QVersionNumber +// and are stored as strings. They may be of the form "1.6.0-beta20200413" +// which, if sorted as a string, will be after "1.6.0" which is bad. Use +// this function to sort that out. (See what I did there? Bwaaaahah!) +bool UpgradeCheck::suggestUpgrade(QString from, QString to) +{ + int fromIndex = 0; + int toIndex = 0; + QVersionNumber fromVersion = QVersionNumber::fromString(from, &fromIndex); + QVersionNumber toVersion = QVersionNumber::fromString(to, &toIndex); + + // We don't have to handle every possible range because the server won't + // have more than a version or two live at any time. + if (fromVersion < toVersion) { + return true; + } + // Just look for the presence of stuff (not even the contents) of the + // string. Shorter string (no "-betaXXX" wins) + if (fromVersion == toVersion) { + if (from.length() - fromIndex > to.length() - toIndex) { + return true; + } + } + return false; +} +// Some day when we have Gunit or equiv, add unit tests for: +//suggestUpgrade(updateVersion, currentVersion_); +//suggestUpgrade("1.6.0-beta20190413", "1.6.0"); +//suggestUpgrade("1.6.0", "1.6.0-beta20190413"); +//suggestUpgrade("1.6.0-beta20190413", "1.7.0"); +//suggestUpgrade("1.7.0", "1.6.0-beta20190413"); + void UpgradeCheck::httpRequestFinished(QNetworkReply* reply) { @@ -272,7 +305,7 @@ void UpgradeCheck::httpRequestFinished(QNetworkReply* reply) upgradeText = upgrade.firstChildElement("overview").text(); // String compare, not a numeric one. Server will return "best first". - if ((updateVersion > currentVersion_) && updateCandidate) { + if (suggestUpgrade(updateVersion, currentVersion_) && updateCandidate) { babelData_.upgradeOffers_++; updateStatus_ = updateNeeded; response = tr("A new version of GPSBabel is available.
" diff --git a/gui/upgrade.h b/gui/upgrade.h index a0e7b6fc9..352043402 100644 --- a/gui/upgrade.h +++ b/gui/upgrade.h @@ -63,6 +63,7 @@ private: QString getOsName(); QString getOsVersion(); QString getCpuArchitecture(); + bool suggestUpgrade(QString from, QString to); private slots: void httpRequestFinished(QNetworkReply* reply);